/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t_sqlserver_list_free.c                            */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/09 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <frcomm.h>
#include <sqlserver/config.h>
#include <sqlserver/sqlserver_core.h>
#include <sqlserver/sqlserver_common.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    Frlist_node *p_st_node = NULL;

    sqlserver_list_free(p_st_node);

}

static void __case2(void)
{
    Frlist_node *p_st_node;

    p_st_node = (Frlist_node *) frmalloc(sizeof(Frlist_node));
    p_st_node->data = NULL;

    sqlserver_list_free(p_st_node);

    frfree(p_st_node);

}

static void __case3(void)
{
    Frlist_node *p_st_node = NULL;
    Frlist_header *p_lst_tmp = NULL;
    Frdata_field *p_frdata_field = NULL;
    char *p_tmp = NULL;

    p_lst_tmp = frlist_create();
    //p_lst_source第一个节点
    //第一个节点
    p_frdata_field = (Frdata_field *) frmalloc(sizeof(Frdata_field));
    memset(p_frdata_field, 0x00, sizeof(Frdata_field));
    p_tmp = (char *) frmalloc(strlen("string") + 1);
    snprintf(p_tmp, strlen("string") + 1, "%s", "string");
    p_frdata_field->p_field_value = p_tmp;
    p_frdata_field->em_data_type = FRSTRING;

    //node
    p_st_node = frlist_node_create(p_frdata_field);
    frlist_add_tail(p_lst_tmp, p_st_node);

    //第二个节点
    p_frdata_field = (Frdata_field *) frmalloc(sizeof(Frdata_field));
    memset(p_frdata_field, 0x00, sizeof(Frdata_field));
    p_tmp = (char *) frmalloc(strlen("int") + 1);
    snprintf(p_tmp, strlen("int") + 1, "%s", "int");
    p_frdata_field->p_field_name = p_tmp;
    p_frdata_field->em_data_type = FRINT;

    //frdata_field->i_value;
    p_frdata_field->p_field_value = frstrdup("10");
    //node
    p_st_node = frlist_node_create(p_frdata_field);
    frlist_add_tail(p_lst_tmp, p_st_node);

    //add to p_lst_source
    p_st_node = frlist_node_create(p_lst_tmp);

    sqlserver_list_free(p_st_node);

    frfree(p_st_node);
}

int add_suite_sqlserver_list_free(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" sqlserver_list_free()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
